﻿using System.Diagnostics;

namespace HBase {
    public class CpuTask :ZtTask {
        private PerformanceCounter pf2;

        private PerformanceCounter pcCpuLoad;
        public float all;
        public float f;

        public CpuTask() {
            time = 1000;
            pcCpuLoad = new PerformanceCounter("Processor" ,"% Processor Time" ,"_Total");
            pcCpuLoad.MachineName = ".";
            pf2 = new PerformanceCounter("Process" ,"% Processor Time" ,Process.GetCurrentProcess().ProcessName);

        }

        public override bool excute() {
            try {
                f = pf2.NextValue();
                all = pcCpuLoad.NextValue();

            } catch {
                pf2 = new PerformanceCounter("Process" ,"% Processor Time" ,Process.GetCurrentProcess().ProcessName);
                pcCpuLoad = new PerformanceCounter("Processor" ,"% Processor Time" ,"_Total");
                pcCpuLoad.MachineName = ".";
            }
            return true;
        }



    }



}
